function xhr(type, url, data) {
      return new Promise(function ( fullfill , reject ) {
            // 判断这个请求是否需要携带数据;
            if (typeof data === "object" && data !== null && !(data instanceof Array)) {
                  var temp = "";
                  for (var attr in data) {
                        temp += "&" + attr + "=" + data[attr];
                  }
                  data = temp.slice(1);
            }
            // 请求方式为get时，同时传递了data数据
            if (type === "GET" && typeof data === "string") {
                  url += "?" + data;
            }
            var xhr = new XMLHttpRequest();
            xhr.open(type, url);
            // 判定请求方式为post，且携带了data数据; 
            if (type === "POST" && typeof data === "string") {
                  xhr.setRequestHeader("content-type", "application/x-www-form-urlencoded");
                  xhr.send(data);
            } else {
                  xhr.send();
            }
            xhr.onreadystatechange = function () {
                  if (xhr.readyState === 4 && xhr.status === 200) {
                        // 如果请求成功则调用回调函数; 
                        
                        fullfill(xhr.responseText);
                  }
            }
      })
}